package com.yww.leetcode2.string;

/**
 * @author yww
 * @description 344. 反转字符串
 * @since 2024/11/18
 */
public class ReverseString344_01 {
    public void reverseString(char[] s) {
        reverse(s, 0, s.length);
    }

    // 双指针解法
    public void reverse(char[] s, int begin, int end) {
        for (int i = begin, j = end - 1; i < end / 2; i++, j--) {
            swap(s, i, j);
        }
    }

    public void swap(char[] s, int i, int j) {
        char temp = s[i];
        s[i] = s[j];
        s[j] = temp;
    }
}
